package com.hkw.daterangepicker

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hkw.daterangepicke.DateDialog
import com.hkw.daterangepicke.DateUtils
import com.hkw.daterangepicke.builder.OptionsDateRangeBuilder
import com.hkw.daterangepicke.listener.OnOptionsSelectListener

class MainActivity : AppCompatActivity() {

    private val TAG = javaClass.simpleName

    var time = -1
    var endTime: String? = null
    var startTime: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setDate()
    }

    private fun setDate() {
        val i: Int = time
        if (i != -1)
            Log.d(TAG, "i != -1")
        if (i != 0) {
            Log.d(TAG, "i != 0")
            if (i != 1) {
                Log.d(TAG, "i != 0, i != 1")
                if (i != 2) {
                    Log.d(TAG, "i != 0, i != 1, i != 2")
                    startTime = ""
                    endTime = ""
                } else {
                    startTime = DateUtils.getOldDate(-2)
                    endTime = DateUtils.getOldDate(-2)
                }
            } else {
                Log.d(TAG, "i != 0, i == 1")
                startTime = DateUtils.getOldDate(-1)
                endTime = DateUtils.getOldDate(-1)
            }
        } else {
            Log.d(TAG, "i == 0")
            startTime = DateUtils.getOldDate(0)
            endTime = DateUtils.getOldDate(0)
        }
        if (time === -1) {
            //this.tvStartTime.setText(startTime)
            //this.tvEndTime.setText(endTime)
        } else {
            //this.tvStartTime.setText("")
            //this.tvEndTime.setText("")
        }
    }


    fun clickGo(view: View) {
        val str = startTime

        /*DateDialog.showDialog(
            this,
            { param1String1, param1String2 ->
                Toast.makeText(
                    this,
                    "start=${param1String1},end=${param1String2}",
                    Toast.LENGTH_SHORT
                ).show()
            }
        )*/
        OptionsDateRangeBuilder(this, object : OnOptionsSelectListener {
            override fun onOptionsSelect(
                startDate: String?,
                endDate: String?,

            ) {
                Log.d(TAG, "startDate=${startDate},endDate=${endDate}")
            }

        }).setEndDateForNow(false).build()
    }
}